package cn.wsalix.templet.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.SimpleEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "SITE_INFO")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false, exclude = { "project" ,"templet","sitePages"})
@ToString(exclude = {"project","templet","sitePages"})
public class SiteInfo extends SimpleEntity {

	private static final long serialVersionUID = 9027885954610744145L;
	private String title;// 站点描述
	private String keywords;// 站点关键字
	private String description;// 描述
	private String language;// 语言
	private String copyright;// 版权
	private String logo;// 站点logo
	private String docs;
	private String generator;
	private String favicon;// 站标
	private String webMaster;// 管理员邮箱
	private String icp;//
	@Temporal(TemporalType.TIMESTAMP)
	private Date pubDate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastBuildDate;
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "PROJECT_ID")
	private Project project;
	@Transient
	private Long projectId;

	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_SITE_TEMP"), name = "TEMP_ID")
	private Templet templet;// 当前站点对应的模板

	@JsonIgnore
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "siteInfo")
	private List<SitePage> sitePages = new ArrayList<SitePage>();

	/**
	 * 处理方式：文件生成到本机[网络服务器]，通过同步机制同步到别的服务器
	 */
	private String webHostPath;// 站点服务器文件保存路径
	private String webHostUrl;// 站点服务器访问路径

}
